package cn.abcsys.devops.application.service;/**
 * Copyright (2017, ) Institute of Software, Chinese Academy of Sciences
 */
import cn.abcsys.devops.application.dao.ApplicationEventsMapper;
import cn.abcsys.devops.application.model.ApplicationEvents;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author xuyuanjia2017@otcaix.iscsa.ac.cn
 * @date 2017/6/28 0028
 * say sth.
 */

@Service("eventsService")
public class EventsService {

    @Resource(name="applicationEventsMapper")
    private ApplicationEventsMapper aem;

    public Map<String,Object> getApplicationEvents(ApplicationEvents ae, Integer page, Integer rows){
        Map<String,Object> resMap = new HashMap<>();
        resMap.put("records",aem.selectCountByApplicationCoreId(ae));
        resMap.put("rows",aem.selectByApplicationCoreId(ae,(page-1)*rows,rows));
        resMap.put("success",true);
        resMap.put("page",page);
        return resMap;
    }

    public Integer insertOneEvent(int applicationCoreId,String type,String description){
        ApplicationEvents ae = new ApplicationEvents();
        ae.setApplicationCoreId(applicationCoreId);
        ae.setApplicationEventDescription(description);
        ae.setApplicationEventStartDatetime(new Date());
        ae.setApplicationEventType(type);
        ae.setApplicationEventCurrentStatus("Done");
        return aem.insertSelective(ae);
    }
}
